package cz.muni.fi.pa165.sme.web.converters;

import cz.muni.fi.pa165.sme.api.to.SportActivityRecordTO;
import cz.muni.fi.pa165.sme.web.common.DateUtils;
import cz.muni.fi.pa165.sme.web.fo.SportActivityRecordFO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

/**
 * @author jirankova
 */
public class SportActivityRecordTO2SportActivityRecordFOConverter implements
		Converter<SportActivityRecordTO, SportActivityRecordFO> {

	@Autowired
	private SportActivityTO2SportActivityFOConverter sportActivityFOConverter;

	@Autowired
	private UserTO2UserFOConverter userFOConverter;

	@Override
	public SportActivityRecordFO convert(final SportActivityRecordTO source) {
		if (source == null) {
			return null;
		}

		final SportActivityRecordFO activityRecordFO = new SportActivityRecordFO();

		activityRecordFO.setActivityStart(DateUtils.convertToDate(source.getActivityStart()));
		activityRecordFO.setActivityStop(DateUtils.convertToDate(source.getActivityStop()));
		activityRecordFO.setDistance(source.getDistance());
		activityRecordFO.setDuration(source.getDuration());
		activityRecordFO.setId(source.getId());
		activityRecordFO.setSportActivity(sportActivityFOConverter.convert(source.getSportActivity()));
		activityRecordFO.setUser(userFOConverter.convert(source.getUser()));

		return activityRecordFO;
	}
}
